From ef1737aaa85168d85f2727cfb880eabc691f6262 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Sat, 29 Oct 2022 22:45:20 -0500 Subject: [PATCH] Don't make it easy to iterate the state_t enum...except when we do. (#939) --- brauniger_iq.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/brauniger_iq.cc b/brauniger_iq.cc index 71c790c1b..7074caac2 100644 --- a/brauniger_iq.cc +++ b/brauniger_iq.cc @@ -48,18 +48,8 @@ namespace { // fix ODR violation with igc num_states }; } -static state_t state; -inline state_t& operator++(state_t& s) // prefix -{ - return s = static_cast(s + 1); -} -inline state_t operator++(state_t& s, int) // postfix -{ - state_t ret(s); - ++s; - return ret; -} +static state_t state; static const int reqd_bytes[num_states] = { 6, 1, 2, 2, 25, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1 }; static void rd_init(const QString& fname) @@ -227,7 +217,12 @@ static int process_data(const unsigned char* data) default: fatal(MYNAME ": Bad internal state\n"); } - ++state; + + // Iterating an enum isn't great and it's less greatr that reqd_byte[] is + // implicitly coupled to our state_t, but here we are with C code forged + // into C++. + state = static_cast (state + 1); + return remaining; } -- 2.30.2